<?php

namespace App\Inventor\Controllers;


use App\Repositories\PatentApplyRepository;
use App\Repositories\PatentFeeRepository;
use App\Services\DashboardService;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Row;
use Encore\Admin\Layout\Content;
use Encore\Admin\Widgets\Table;
use Encore\Admin\Facades\Admin;
use App\Http\Controllers\Controller;
use App\Repositories\PatentRepository;


class HomeController extends Controller
{
    protected $title = '工作台';

    public $applyRepository;
    public $patentRepository;
    protected $patentFeeRepository;
    protected $dashboardService;

    public function __construct(DashboardService $dashboardService,PatentApplyRepository $applyRepository, PatentRepository $patentRepository, PatentFeeRepository $patentFeeRepository)
    {
        $this->applyRepository = $applyRepository;
        $this->patentRepository = $patentRepository;
        $this->patentFeeRepository = $patentFeeRepository;
        $this->dashboardService = $dashboardService;
    }

    public function index(Content $content)
    {
        $admin = Admin::user();
        return $content
            ->title($this->title)
            //->row(view('tip'))
            ->row(function (Row $row) use ($admin) {
                $row->column(6, function (Column $column) use ($admin) {
                    $column->append($this->dashboardService->applying($admin));
                });
                $row->column(6, function (Column $column) use ($admin) {
                    $column->append($this->dashboardService->documents($admin));
                });
            });
    }

    protected function patentMonitor()
    {
        $user = Admin::user();
        $amount1 = $this->patentFeeRepository->totalByLastDate($user, 1);
        $amount2 = $this->patentFeeRepository->totalByLastDate($user, 3);
        $amount3 = $this->patentFeeRepository->totalByLastDate($user, 6);

        return (new Table(['时间', '应缴费金额', '操作'], [
            ['一个月内', $amount1, '<a href="' . admin_route("patent.fees.index", ['_selector[last_time]' => 1]) . '">查看</a>'],
            ['三个月内', $amount2, '<a href="' . admin_route("patent.fees.index", ['_selector[last_time]' => 2]) . '">查看</a>'],
            ['六个月内', $amount3, '<a href="' . admin_route("patent.fees.index", ['_selector[last_time]' => 3]) . '">查看</a>'],
        ]));
    }

    protected function link($title, $href)
    {
        return <<<LINK
  <a href="$href">{$title}</a>
LINK;
    }
}
